package tgc.edu.exam.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.annotation.CreatedBy;

import com.fasterxml.jackson.annotation.JsonIgnore;

import tgc.edu.exam.custom.BaseEntity;
import tgc.edu.exam.custom.dict.entity.TbClassState;
import tgc.edu.exam.custom.dict.entity.TbClassType;

/**
 * 班级
 * */
@Entity
public class TbClass extends BaseEntity<UUID> {
	private String name;		//班级名称
	private String subject;		//培训主题
	private TbClassType ctype;		//班级类型
	private Integer classSize;	//班级人数
	private String regBeginTime;	//报名开始时间
	private String regEndTime;		//报名结束时间
	private String startTime;	//开班日期
	private String closeTime;	//结业日期
	private TbClassState classStatus;		//班级状态
	private String memo;		//备注
	private Teacher teacherId;		//班主任；
	private Teacher instructor; //辅导员
	private Teacher logistics; //后勤服务员
	private Integer classNumber;	//组数
	@JsonIgnore
	List<Student> children = new ArrayList<>(); 	//班级学生
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	@ManyToOne
	@CreatedBy
	public TbClassType getCtype() {
		return ctype;
	}
	public void setCtype(TbClassType ctype) {
		this.ctype = ctype;
	}
	public Integer getClassSize() {
		return classSize;
	}
	public void setClassSize(Integer classSize) {
		this.classSize = classSize;
	}
	public String getRegBeginTime() {
		return regBeginTime;
	}
	public void setRegBeginTime(String regBeginTime) {
		this.regBeginTime = regBeginTime;
	}
	public String getRegEndTime() {
		return regEndTime;
	}
	public void setRegEndTime(String regEndTime) {
		this.regEndTime = regEndTime;
	}
	public String getStartTime() {
		return startTime;
	}
	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}
	public String getCloseTime() {
		return closeTime;
	}
	public void setCloseTime(String closeTime) {
		this.closeTime = closeTime;
	}
	@ManyToOne
	@CreatedBy
	public TbClassState getClassStatus() {
		return classStatus;
	}
	public void setClassStatus(TbClassState classStatus) {
		this.classStatus = classStatus;
	}
	public String getMemo() {
		return memo;
	}
	public void setMemo(String memo) {
		this.memo = memo;
	}
	@ManyToOne
	@CreatedBy
	public Teacher getTeacherId() {
		return teacherId;
	}
	public void setTeacherId(Teacher teacherId) {
		this.teacherId = teacherId;
	}
	public Integer getClassNumber() {
		return classNumber;
	}
	public void setClassNumber(Integer classNumber) {
		this.classNumber = classNumber;
	}
	@OneToMany(mappedBy="tbClass")
	public List<Student> getChildren() {
		return children;
	}
	public void setChildren(List<Student> children) {
		this.children = children;
	}
	public TbClass() {
		super();
		// TODO Auto-generated constructor stub
	}
	public TbClass(UUID id, Boolean isUsed, String createName, String createDate, String updateName,
			String updateDate) {
		super(id, isUsed, createName, createDate, updateName, updateDate);
		// TODO Auto-generated constructor stub
	}
	public TbClass(UUID id, Boolean isUsed) {
		super(id, isUsed);
		// TODO Auto-generated constructor stub
	}
	public TbClass(UUID id) {
		super(id);
		// TODO Auto-generated constructor stub
	}
	public TbClass(UUID id, Boolean isUsed, String createName, String createDate, String updateName, String updateDate,
			String name, String subject, TbClassType ctype, Integer classSize, String regBeginTime, String regEndTime,
			String startTime, String closeTime, TbClassState classStatus, String memo, Teacher teacherId,
			Teacher instructor, Teacher logistics, Integer classNumber, List<Student> children) {
		super(id, isUsed, createName, createDate, updateName, updateDate);
		this.name = name;
		this.subject = subject;
		this.ctype = ctype;
		this.classSize = classSize;
		this.regBeginTime = regBeginTime;
		this.regEndTime = regEndTime;
		this.startTime = startTime;
		this.closeTime = closeTime;
		this.classStatus = classStatus;
		this.memo = memo;
		this.teacherId = teacherId;
		this.instructor = instructor;
		this.logistics = logistics;
		this.classNumber = classNumber;
		this.children = children;
	}
	@ManyToOne
	@CreatedBy
	public Teacher getInstructor() {
		return instructor;
	}
	public void setInstructor(Teacher instructor) {
		this.instructor = instructor;
	}
	@ManyToOne
	@CreatedBy
	public Teacher getLogistics() {
		return logistics;
	}
	public void setLogistics(Teacher logistics) {
		this.logistics = logistics;
	}
	
	@Transient
	public String getStuName() {
		List<Student> list = getChildren();
		String str="";
		for (Student s : list) {
			str += s.getName()+", ";
		}
		if(!str.equals("")){
			str = str.substring(0, str.length()-2);
		}
		return str;
	}
	
}
